import { CommonModel, ListResponse, PagerQuery } from '.'
import { authorizeRequest, unauthorizeRequest } from '../util/http'

const ROUTER = '/v1/public'

type GetPublicPictureListParams = PagerQuery
export type PictureListResponse = ListResponse<Picture>
export interface Picture extends CommonModel {
    title: string;
    imageUrl: string;
    desc: string;
    public: boolean;
    userId: number;
    categoryId: number;
}
export const apiGetPublicPictureList = async (params: GetPublicPictureListParams) => {
    return (await unauthorizeRequest.get<PictureListResponse>(ROUTER, { params })).data
}

export interface TogglePublicParams {
    pictureId: number
    public: boolean
}

export const apiPutPublicPicture = async (params: TogglePublicParams) => {
    return (await authorizeRequest.put<object>(ROUTER + '/' + params.pictureId, params)).data
}